# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
	@type
	
	def sort_td_class_helper(param)
		result = 'class="sortup"' if params[:sort] == param
		result = 'class="sortdown"' if params[:sort] == param + "_reverse"
		return result
	end


	def sort_link_helper(text, param)
		key = param
		key += "_reverse" if params[:sort] == param
		options = {
			:url => {:action => 'list', :params => params.merge({:sort => key, :page => nil})},
			:update => 'resultSet',
			:before => "Element.show('spinner')",
			:success => "Element.hide('spinner')"
		}
		html_options = {
			:title => "Sort by this field",
			:href => url_for(:action => 'list', :params => params.merge({:sort => key, :page => nil}))
		}
		link_to_remote(text, options, html_options)
	end


	def get_next_result_set_type
		if (@type.nil? || @type == "even")
			@type = "odd"
		else
			@type = "even"
		end
		return @type
	end


  def get_spinner
    return image_tag("spinner.gif",	:align => "absmiddle", :border => 0, :id => "spinner", :style => "display: none;")
  end


  def get_changes_saved_text(object)
    object.updated_at.strftime("Changes saved (%H:%M:%S)")
  end

end
